﻿using System.Collections.Generic;
using System.Linq;
using System.Data;

namespace StudentInfo.Areas.StudentArea.Services
{
    public class ExamService
    {
        public static List<Exam> GetAll()
        {
            using (var context = new StudentInfoEntities())
            {
                return context.Exams.ToList();
            }
        }

        public static Exam Get(int examId)
        {
            using (var context = new StudentInfoEntities())
            {
                return context.Exams.FirstOrDefault(s => s.Id == examId);
            }
        }

        public static void Save(Exam exam)
        {
            using (var context = new StudentInfoEntities())
            {
                context.Exams.Attach(exam);
                context.Entry(exam).State = EntityState.Modified;
                context.SaveChanges();
            }
        }

        public static void Create(Exam exam)
        {
            using (var context = new StudentInfoEntities())
            {
                context.Exams.Add(exam);
                context.SaveChanges();
            }
        }

        public static void Delete(Exam exam)
        {
            using (var context = new StudentInfoEntities())
            {
                context.Entry(exam).State = EntityState.Deleted;
                context.SaveChanges();
            }
        }
    }
}